package com.example.market.controller;

import com.example.market.pojo.Category;
import com.example.market.service.CategoryService;
import com.example.market.util.JsonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    private JsonResponse jsonResponse;

    private CategoryService categoryService;

    @Autowired
    public void setJsonResponse(JsonResponse jsonResponse) {
        this.jsonResponse = jsonResponse;
    }
    @Autowired
    public void setCategoryService(CategoryService categoryService) {
        this.categoryService = categoryService;
    }

    @GetMapping("")
    public JsonResponse category() {
        List<Category> categories = categoryService.getAll();
        jsonResponse.success("001", categories);
        return jsonResponse;
    }

}
